package ystp.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import ystp.model.Ysuser;
import ystp.service.YsuserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class PageController {

    @Resource
    YsuserService ddYsuserService;

    @RequestMapping("main/login")
    public String Login(HttpServletRequest request) {

        return "main/login";

    }

    @RequestMapping("main/xiangmu")
    public String Listxiangmu(HttpServletRequest request) {

        if (isLogin(request)) {
            return "main/list_xiangmu";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/operatorprint")
    public String operatorprint(HttpServletRequest request) {

        if (isLogin(request)) {
            return "main/list_print_operator";
        } else {
            return "main/login";
        }

    }


    @RequestMapping("main/renyuan")
    public String Listrenyuan(HttpServletRequest request) {

        if (isLogin(request)) {
            return "main/list_renyuan";
        } else {
            return "main/login";
        }

    }
    @RequestMapping("main/renyuanfenpei")
    public String renyuanfenpei(HttpServletRequest request) {

        if (isLogin(request)) {
            return "main/List_renyuanfenpei";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/jindu")
    public String jindu(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            if("35".equals(mmXiangmuleixing)){
                return "main/list_jindu_pingui";
            }else{
                return "main/list_jindu";
            }

           /* if(mmXiangmuleixing!=null && (mmXiangmuleixing.equals("4")||mmXiangmuleixing.equals("5")||mmXiangmuleixing.equals("6")||mmXiangmuleixing.equals("7"))){
                return "main/list_bufenjjindui";
            }
            if("2".equals(mmXiangmuleixing)){
                return "main/list_jindu_tongke";
            }
            if("3".equals(mmXiangmuleixing)){
                return "main/list_jindu_zhuanke";
            }*/
           /* return "main/list_jindu_kangjun";*/
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/huizongbiao")
    public String huizongbiao(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_huizongbiao";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/xinguotanhuizongbiao")
    public String xinguotanhuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_xinguotanhuizongbiao";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/chuangxinchanpinhuizongbiao")
    public String chuangxinchanpinhuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_chuangxinchanpinhuizongbiao";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/yuecaihuizongbiao")
    public String yuecaihuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_yuecaihuizongbiao";
        } else {
            return "main/login";
        }

    }
    @RequestMapping("main/tongkehuizongbiao")
    public String tongkehuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_tongkehuizongbiao";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/xinyaoshenqinghuizongbiao")
    public String xinyaoshenqinghuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_xinyaoshenqinghuizongbiao";
        } else {
            return "main/login";
        }

    }


    @RequestMapping("main/zhuankehuizongbiao")
    public String zhuankehuizongbiao(HttpServletRequest request,ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_zhuankehuizongbiao";
        } else {
            return "main/login";
        }

    }

    @RequestMapping("main/kangjun")
    public String ListKangjun(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_kangjun";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("main/tongkeyaopin")
    public String ListTongke(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_tongkeyaopin";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("main/zhuankeyaopin")
    public String ListZhuanke(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_zhuankeyaopin";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/yuecaikangjun")
    public String ListyuecaiKangjun(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_yuecaikangjun";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/xinguotan")
    public String Listxinguotan(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_xinguotan";
        } else {
            return "main/login";
        }
    }


    @RequestMapping("main/chuangxinchanpin")
    public String Listchuangxinchanpin(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_chuangxinchanpin";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/xinyaoshenqing")
    public String Listxinyaoshenqing(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_xinyaoshenqing";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("vote/xiangmu")
    public String votexiangmu(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            HttpSession session = request.getSession();
            String mmUserid=session.getAttribute("Id").toString();
            Ysuser mmYsuser=ddYsuserService.findOne(mmUserid);
            if("1".equals(mmYsuser.getShifouxiugai())){
                return "vote/list_xiangmu_vote";
            }else {
                return "main/modifypassword";
            }


        } else {
            return "main/login";
        }
    }

    @RequestMapping("vote/vote")
    public String vote(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            String mmLunci = request.getParameter("lunci").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuleixing", mmXiangmuleixing);
            map.put("lunci", mmLunci);
            return "vote/list_ty_vote";
//            if("35".equals(mmXiangmuleixing)){
//                return "vote/list_fujianpingui_vote";
//            }else{
//                return "vote/list_fujianot_vote";
//            }
           /* if("1".equals(mmXiangmuleixing)){
                return "vote/list_kangjun_vote";
            }
            if("2".equals(mmXiangmuleixing)){
                return "vote/list_tongke_vote";
            }
            if("3".equals(mmXiangmuleixing)){
                return "vote/list_zhuanke_vote";
            }
            if("4".equals(mmXiangmuleixing)){
                return "vote/list_xinguotan_vote";
            }
            if("5".equals(mmXiangmuleixing)){
                return "vote/list_chuangxinchanpin_vote";
            }
            if("6".equals(mmXiangmuleixing)){
                return "vote/list_xinyaoshenqing_vote";
            }
            if("7".equals(mmXiangmuleixing)){
                return "vote/list_yuecaikangjun_vote";
            }
            if("8".equals(mmXiangmuleixing)){
                return "vote/list_shengchanqiyelinxuan_vote";
            }*/
           /* if("11".equals(mmXiangmuleixing)||"12".equals(mmXiangmuleixing)||"13".equals(mmXiangmuleixing)||"14".equals(mmXiangmuleixing)){
                return "vote/list_shengchanqiyelinxuan_vote";
            }*/
        } else {
            return "main/login";
        }
    }


    @RequestMapping("vote/kangjun")
    public String voteKangjun(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            HttpSession session = request.getSession();
            String mmUserid=session.getAttribute("Id").toString();
            Ysuser mmYsuser=ddYsuserService.findOne(mmUserid);
            if("1".equals(mmYsuser.getShifouxiugai())){
                return "vote/list_kangjun_vote";
            }else {
                return "main/modifypassword";
            }


        } else {
            return "main/login";
        }
    }

    @RequestMapping("vote/yuecaikangjun")
    public String voteyuecaiKangjun(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            return "vote/list_yuecaikangjun_vote";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("vote/xinguotan")
    public String votexinguotan(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            return "vote/list_xinguotan_vote";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("vote/chuangxinchanpin")
    public String voteychuangxinchanpin(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            return "vote/list_chuangxinchanpin_vote";
        } else {
            return "main/login";
        }
    }


    @RequestMapping("vote/modifypassword")
    public String modifypassword(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            return "main/modifypassword";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printShengchanqiye")
    public String printShengchanqiye(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_shengchanqiye";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("main/printTy")
    public String printTy(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_ty";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printKangjunyaowu")
    public String printKangjunyaowu(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_kangjunyaowu";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("main/printTongkeyaopin")
    public String printTongkeyaopin(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_tongkeyaopin";
        } else {
            return "main/login";
        }
    }
    @RequestMapping("main/printZhuankeyaopin")
    public String printZhuankeyaopin(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_zhuankeyaopin";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printXinguotan")
    public String printXinguotan(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_xinguotan";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printChuangxinchanpin")
    public String printChuangxinchanpin(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_chuangxinchanpin";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printYuecaiyaowu")
    public String printYuecaiyaowu(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_yuecaiyaowu";
        } else {
            return "main/login";
        }
    }

    @RequestMapping("main/printXinyaoshenqing")
    public String printXinyaoshenqing(HttpServletRequest request, ModelMap map) {
        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            String mmXiangmuleixing = request.getParameter("xiangmuleixing").toString();
            map.put("xiangmuId", mmXiangmuId);
            map.put("xiangmuLeixing", mmXiangmuleixing);
            return "main/list_print_xinyaoshenqing";
        } else {
            return "main/login";
        }
    }

    //上传
    @RequestMapping("main/upload_batch.html")
    public String UploadBatch(ModelMap map, HttpServletRequest request) {

        if(!isLogin(request)) {
            return "redirect:/main/login.html";
        }

        String mmFuJianPath = request.getParameter("fujianpath").toString();
        String mmFileSize = request.getParameter("filesize").toString();
        map.put("filetype", "batch");
        map.put("fujianpath", mmFuJianPath);
        map.put("filesize", mmFileSize);
        return "main/UploadBatch";
    }

    @RequestMapping("main/shengchanqiyelinxuan")
    public String Listshengchanqiyelinxuan(HttpServletRequest request, ModelMap map) {

        if (isLogin(request)) {
            String mmXiangmuId = request.getParameter("xiangmuid").toString();
            map.put("xiangmuId", mmXiangmuId);
            return "main/list_shengchanqiyelinxuan";
        } else {
            return "main/login";
        }
    }

    public boolean isLogin(HttpServletRequest request) {
        HttpSession session = request.getSession();
        if (session == null || session.getAttribute("Id") == null) {
            return false;
        }
        return true;
    }

}
